﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

using RVNetworkLib;

namespace SimpleServer
{
    public partial class Form1 : Form
    {
        private Server _server;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (_server != null) return;

            RoomStatus rs = new RoomStatus();
            rs.RoomName = _txtRoomName.Text;
            rs.MapName = _txtMapName.Text;
            rs.Mode = GameMode.Normal;
            rs.RoomID = 0;
            rs.NumUser = 0;
            rs.MaxUser = 10;
            rs.State = RoomState.Open;
            rs.Users = new List<ActiveClientStatus>();

            _server = new Server(rs);
            AppendLog("Server Launch");
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_server != null)
            {
                _server.Close();
                _server = null;

                AppendLog("Server Shutdown");
            }
        }

        private void AppendLog(string msg)
        {
            _listMsg.Items.Add(msg);
        }

        private void ClearLog(object sender, EventArgs e)
        {
            _listMsg.Items.Clear();
        }

        private void CloseServer(object sender, EventArgs e)
        {
            if (_server == null) return;

            _server.Close();
            _server = null;

            AppendLog("Server Shutdown");
        }
    }
}
